#include "sms.h"

#include "log.h"

namespace chat {
bool SpugSMSCodeSender::send(const std::string& code,
                             const std::string& phone) {
    const std::string url = "https://push.spug.cc/send/" + api_key_ +
                            "?code=" + code + "&targets=" + phone;

    httplib::Result res = client_->Get(url);
    // 检查请求结果
    if (res) {
        if (res->status == 200) {
            LOG_DEBUG("短信发送成功, 响应：{}", res->body);
            return true;

        } else {
            LOG_ERROR("短信发送失败, HTTP 状态码：{}", res->status);
            return false;
        }
    } else {
        LOG_ERROR("请求失败，错误信息：{}", httplib::to_string(res.error()));
        return false;
    }
}
}  // namespace chat
